package ganga.custodian.settings;

import ganga.custodian.CustodianApplication;
import ganga.custodian.R;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class AccelerometrPropertyActivity extends Activity {
	SensorManager sensorManager;
	Sensor accelerometerSensor;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.accelerometrpropertyactivity);
		getAdapter();
		setSettingToTextView();
		setCurrentTheme();
		
	}
	@Override
	protected void onResume() {
		super.onResume();
		setCurrentTheme();
	}

	/**
	 * Выставляет свойства акселерометра в текстовые поля
	 */
	private void setSettingToTextView() {
		try{
		TextView nameAdapter=(TextView)findViewById(R.id.accelerometrpropertyname);
		TextView vendorAdapter = (TextView)findViewById(R.id.accelerometrpropertyvendor);
		TextView versionAdapter = (TextView)findViewById(R.id.accelerometrpropertyversion);
		TextView maxRangeAdapter = (TextView)findViewById(R.id.accelerometrpropertymaxrange);
		TextView powerAdapter = (TextView)findViewById(R.id.accelerometrpropertypower);
		TextView resolutionAdapter = (TextView)findViewById(R.id.accelerometrpropertyresolution);
		TextView typeAdapter = (TextView)findViewById(R.id.accelerometrpropertytype);
		nameAdapter.setText(accelerometerSensor.getName());
		vendorAdapter.setText(accelerometerSensor.getVendor());
		Integer version =accelerometerSensor.getVersion();
		versionAdapter.setText(version.toString());
		Float maxRange = accelerometerSensor.getMaximumRange();
		maxRangeAdapter.setText(maxRange.toString());
		Float power = accelerometerSensor.getPower();
		powerAdapter.setText(power.toString());
		Float resolution = accelerometerSensor.getResolution();
		resolutionAdapter.setText(resolution.toString());
		Integer type = accelerometerSensor.getType();
		typeAdapter.setText(type.toString());
		}
		catch (Exception e) {
			Toast.makeText(this, R.string.dataLoadingisuncorrect, Toast.LENGTH_SHORT).show();
		}
	}

	/**
	 * Получаем ссылку на адаптер желаемого типа
	 */
	private void getAdapter() {
		sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
		List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
		if (sensors.size() > 0) {
			for (Sensor sensor : sensors) {
				switch (sensor.getType()) {
				case Sensor.TYPE_ACCELEROMETER:
					if (accelerometerSensor == null)
						accelerometerSensor = sensor;
					break;
				default:
					break;
				}
			}
		}
	}
	/**
	 * Выставляет текущую тему
	 */
	private void setCurrentTheme(){
		TextView nameAdr=(TextView)findViewById(R.id.accelerometrpropertyname);
		setTextViewColor(nameAdr);
		TextView vendorAdr = (TextView)findViewById(R.id.accelerometrpropertyvendor);
		setTextViewColor(vendorAdr);
		TextView versionAdr = (TextView)findViewById(R.id.accelerometrpropertyversion);
		setTextViewColor(versionAdr);
		TextView maxRangeAdr = (TextView)findViewById(R.id.accelerometrpropertymaxrange);
		setTextViewColor(maxRangeAdr);
		TextView powerAdr = (TextView)findViewById(R.id.accelerometrpropertypower);
		setTextViewColor(powerAdr);
		TextView resolutionAdr = (TextView)findViewById(R.id.accelerometrpropertyresolution);
		setTextViewColor(resolutionAdr);
		TextView typeAdr = (TextView)findViewById(R.id.accelerometrpropertytype);
		setTextViewColor(typeAdr);
		TextView textView1 = (TextView)findViewById(R.id.accelerometrpropertyTextView1);
		setTextViewColor(textView1);
		TextView textView2 = (TextView)findViewById(R.id.accelerometrpropertyTextView2);
		setTextViewColor(textView2);
		TextView textView3 = (TextView)findViewById(R.id.accelerometrpropertyTextView3);
		setTextViewColor(textView3);
		TextView textView4 = (TextView)findViewById(R.id.accelerometrpropertyTextView4);
		setTextViewColor(textView4);
		TextView textView5 = (TextView)findViewById(R.id.accelerometrpropertyTextView5);
		setTextViewColor(textView5);
		TextView textView6 = (TextView)findViewById(R.id.accelerometrpropertyTextView6);
		setTextViewColor(textView6);
		TextView textView7 = (TextView)findViewById(R.id.accelerometrpropertyTextView7);
		setTextViewColor(textView7);
		LinearLayout thisLayout =(LinearLayout)findViewById(R.id.accelerometrpropertiesLayout);
		thisLayout.setBackgroundColor(CustodianApplication.getInstance().selectTheme.backGround);
	}
	private void setTextViewColor(TextView textView){
		textView.setTextColor(CustodianApplication.getInstance().selectTheme.firstColour);
	}

}
